package ahblue.cn.tanzi.ui.msg;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

import ahblue.cn.tanzi.R;
import ahblue.cn.tanzi.adapter.BRAdapter;
import ahblue.cn.tanzi.adapter.RvHolder;
import ahblue.cn.tanzi.jmessage.im.base.BaseActivity;
import ahblue.cn.tanzi.model.home.SpecalModel;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @author pink-jackstraw
 * @date 2018/11/10
 * @describe 新的朋友
 */
public class NewFriendActivity extends BaseActivity {

    @BindView(R.id.recy)
    RecyclerView recyview;
    @BindView(R.id.refresh)
    SwipeRefreshLayout swipeRefreshLayout;
    private BRAdapter<SpecalModel> adapter;
    private List<SpecalModel> dataList = new ArrayList<>();
    private int page = 0;

    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case 1:
                    swipeRefreshLayout.setRefreshing(false);
                    adapter.notifyDataSetChanged();
                    //swipeRefreshLayout.setEnabled(false);
                    break;
                default:
                    break;
            }
        }
    };

    public static void into(Activity activity){
        activity.startActivity(new Intent(activity,NewFriendActivity.class));
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_newfriend_list);
        ButterKnife.bind(this);
        initView();
        initData();
    }

    private void initData() {
//        for (int x = 0; x < 30; x++) {
//            dataList.add(new SpecalModel());
//        }
        adapter.notifyDataSetChanged();
    }

    private void initView() {
        recyview.setLayoutManager(new LinearLayoutManager(this));
        adapter = new BRAdapter<SpecalModel>(this, R.layout.activity_collect_item, dataList) {
            @Override
            protected void convert(RvHolder holder, SpecalModel specalModel, int position) {

            }
        };
        recyview.setAdapter(adapter);
        swipeRefreshLayout.setColorSchemeResources(R.color.colorPrimary);
        swipeRefreshLayout.setSize(SwipeRefreshLayout.LARGE);
//        swipeRefreshLayout.setProgressBackgroundColor(R.color.colorAccent);
        //swipeRefreshLayout.setPadding(20, 20, 20, 20);
        //swipeRefreshLayout.setProgressViewOffset(true, 100, 200);
        //swipeRefreshLayout.setDistanceToTriggerSync(50);
        swipeRefreshLayout.setProgressViewEndTarget(true, 100);
        swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        dataList.clear();
                        page = 0;
                        initData();
                        mHandler.sendEmptyMessage(1);
                    }
                }).start();
            }
        });
    }

    @OnClick(R.id.btn_back)
    public void onViewClicked() {
        finish();
    }
}
